package base.thread_JUC2.chapter04.demo04;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

public class Task implements Callable<Result> {
    private String name;
    public Task(String name){
        this.name = name;
    }

    @Override
    public Result call() throws Exception {
        long duration = (long)(Math.random() * 10);
        TimeUnit.SECONDS.sleep(duration);

        int sum =0;
        for (int i = 0; i < 5; i++) {
            sum += (int)(Math.random()*100);
        }

        Result result = new Result();
        result.setName(name);
        result.setValue(sum);

        return result;
    }
}
